<?php

namespace App\Repository\Msq;

use App\Model\Agency\AgencyCompanyModel;
use App\Repository\RepositoryGeneral;
use Hyperf\Di\Annotation\Inject;

class AgencyCompanyMsq extends RepositoryGeneral
{
    #[Inject]
    public AgencyCompanyModel $agencyCompanyModel;

    public function addAgencyCompany(array $data){
        $res = $this->agencyCompanyModel->create($data);
        return [
            'agency_company_id' => $res->id
        ];
    }

    public function getAgencyCompanyInfo(int $id){
        return $this->agencyCompanyModel
            ->withCustomCondition()
            ->where('id',$id)
            ->where('status',1)
            ->first();
    }

    public function getAgencyCompanyList(int $page , array $filters = [],array $select = ['*']){
        return $this->agencyCompanyModel
            ->withCustomCondition()
            ->select($select)
            ->where('status',1)
            ->paginate($page);
    }

    public function getAgencyCompanyByName(string $name,array $select = ["*"]){
       return $this->toArray($this->agencyCompanyModel
           ->withCustomCondition()
           ->select($select)
           ->where('agency_company_name',$name)
           ->where('status',1)
           ->first());
    }

    public function delAgencyCompanyByIds(array $ids){
        return $this->agencyCompanyModel
            ->withCustomCondition()
            ->whereIn('id',$ids)
            ->update([
                'status' => 2
            ]);
    }

    public function editAgencyCompany(int $id,array $params){
        if(isset($params['id'])){
            unset($params['id']);
        }
        return $this->agencyCompanyModel
            ->withCustomCondition()
            ->where('id',$id)
            ->update($params);
    }

    public function getAgencyCompanySelect(){
        return $this->toArray($this->agencyCompanyModel
            ->withCustomCondition()
            ->select(['id as key','agency_company_name as value'])
            ->where('status',1)
            ->get());
    }


}